import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

/**
 * 
 *Gui of remove book from catalog window for the user's use
 */
public class RemoveBFCGui extends JPanel implements ActionListener
{

	public static final long serialVersionUID = 1L;
	/** array of strings for the returned result*/
	public String[] res;
	public DefaultListModel listModel1;
	/** Indicate that a search was execute or not execute*/
	boolean seflag=false;
	public String value;  //  @jve:decl-index=0:
	public JList jBookDetailsList;
	public JLabel Title = null;
	public JLabel Author = null;
	public JLabel Summery = null;
	public JLabel Language = null;
	public JLabel Keywords = null;
	public JLabel Price = null;
	public JLabel Index = null;
	public JLabel Pdf = null;
	public JLabel Doc = null;
	public JLabel Fb2 = null;
	public JScrollPane jScrollPane = null;
	public JButton jButtonBack = null;
	public JButton jButtonRemovBook = null;
	public JLabel jLabelSerial = null;
	public JLabel jLabelSerial1 = null;
	public String serial123;  //  @jve:decl-index=0:
	
	public JScrollPane jScrollLanguage = null;
	public JList jLanguageList = null;
	public JList jAuthorList = null;
	public JScrollPane jScrollAuthor = null;
	public DefaultListModel listModel2;
	public JLabel numOS = null;
	/**
	 * This is the default constructor
	 */
	public RemoveBFCGui()
	{
		super();
		initialize();
	}

	/**
	 * This method initializes remove book from catalog window
	 * bdetails - array of strings get the book details
	 * language - array of strings gets the book's languages
	 * author - array of strings gets the book's authors names
	 * 
	 * @return void
	 */
	public void initialize() 
	{
		String [] bdetails=null;
		String [] language = null;
		String [] author = null;
		jLabelSerial1 = new JLabel();
		jLabelSerial1.setBounds(new Rectangle(245, 110, 90, 30));
		jLabelSerial1.setText("JLabel");
		jLabelSerial = new JLabel();
		jLabelSerial.setBounds(new Rectangle(190, 110, 55, 30));
		jLabelSerial.setText("Serial :");
		this.setSize(650, 450);
		this.setLayout(null);
		value = (String) Main.searchBookG.SearchResult.getSelectedValue();
		Main.welcomeScreen.d_Retrieve_Set(value);
		bdetails  = Main.welcomeScreen.res;
		serial123 = bdetails[0];
		jLabelSerial1.setText(bdetails[0]);
		JLabel welcomeLabel = new JLabel("Remove Book From Catalog");
		welcomeLabel.setFont(new Font(Font.SANS_SERIF ,Font.ITALIC,20));
		welcomeLabel.setBounds(200,20,300,50);
		listModel1=new DefaultListModel();
		for(int i=1;i<bdetails.length-1;i++)
			listModel1.addElement(bdetails[i]);
		jBookDetailsList = new JList(listModel1);
		jBookDetailsList.setEnabled(false);
		jScrollPane = new JScrollPane();
		jScrollPane.setBounds(new Rectangle(100, 150, 400, 220));
		jScrollPane.setViewportView(jBookDetailsList);
		numOS = new JLabel();
		numOS.setBounds(new Rectangle(10, 283, 100, 21));
		numOS.setText("Num of search:");
		Fb2 = new JLabel();
		Fb2.setBounds(new Rectangle(10, 263, 60, 21));
		Fb2.setText("FB2:");
		Doc = new JLabel();
		Doc.setBounds(new Rectangle(10, 243, 60, 21));
		Doc.setText("DOC:");
		Pdf = new JLabel();
		Pdf.setBounds(new Rectangle(10, 225, 60, 21));
		Pdf.setText("PDF:");
		Price = new JLabel();
		Price.setBounds(new Rectangle(10, 303, 60, 21));
		Price.setText("Price:");
		Index = new JLabel();
		Index.setBounds(new Rectangle(10, 205, 60, 21));
		Index.setText("Index:");
		Keywords = new JLabel();
		Keywords.setBounds(new Rectangle(10, 187, 65, 20));
		Keywords.setText("Keywords:");
		Language = new JLabel();
		Language.setBounds(new Rectangle(510, 120, 65, 19));
		Language.setText("Language:");
		Summery = new JLabel();
		Summery.setBounds(new Rectangle(10, 170, 65, 19));
		Summery.setText("Summery:");
		Author = new JLabel();
		Author.setBounds(new Rectangle(510, 253, 50, 19));
		Author.setText("Author:");
		Title = new JLabel();
		Title.setBounds(new Rectangle(10, 150, 50, 19));
		Title.setText("Title:");
		language = Main.welcomeScreen.res2;
		listModel2=new DefaultListModel();
		for(int i=0;i<language.length;i++)
			listModel2.addElement(language[i]);
		jLanguageList=new JList(listModel2);
		jLanguageList.setEnabled(false);
		jScrollLanguage = new JScrollPane();
		jScrollLanguage.setBounds(510, 150, 140, 100);
		jScrollLanguage.setViewportView(jLanguageList);
		
		
		author = Main.welcomeScreen.res1;
		listModel2=new DefaultListModel();
		for(int i=0;i<author.length;i++)
			listModel2.addElement(author[i]);
		jAuthorList=new JList(listModel2);
		jAuthorList.setEnabled(false);
		jScrollAuthor = new JScrollPane();
		jScrollAuthor.setBounds(510, 270, 140, 100);
		jScrollAuthor.setViewportView(jAuthorList);
		this.add(jScrollAuthor,null);
		this.add(jScrollLanguage,null);
		this.add(numOS,null);
		
		this.add(welcomeLabel);
		this.add(jScrollPane);
		this.add(Title, null);
		this.add(Author, null);
		this.add(Summery, null);
		this.add(Language, null);
		this.add(Keywords, null);
		this.add(Price, null);
		this.add(Index, null);
		this.add(Pdf, null);
		this.add(Doc, null);
		this.add(Fb2, null);
		this.add(getJButtonBack(), null);
		this.add(getJButtonRemovBook(), null);
		this.add(jLabelSerial, null);
		this.add(jLabelSerial1, null);
	}

	/**
	 * This method initializes jButtonBack and set listener on this button 
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getJButtonBack() {
		if (jButtonBack == null) {
			jButtonBack = new JButton();
			jButtonBack.setBounds(new Rectangle(536, 20, 95, 26));
			jButtonBack.setText("Back");
			jButtonBack.addActionListener(this);
		}
		return jButtonBack;
	}

	@Override
	/**
	 * /**
	 * this method is activated when one of the listeners was triggered
	 */
	
	public void actionPerformed(ActionEvent ae) 
	{
		if (ae.getSource() == getJButtonBack())
		{
			this.setEnabled(false);
			this.setVisible(false);
			Main.log.frame.setSize(730, 560);
			Main.log.frame.add(Main.searchBookG);
			Main.searchBookG.setEnabled(true);
			Main.searchBookG.setVisible(true);
		}
		if (ae.getSource() == getJButtonRemovBook())
		{
			Main.removeFromCC.removeBFC();
		}
		
	}

	/**
	 * This method initializes jButtonRemovBook	and set listener this button
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getJButtonRemovBook() {
		if (jButtonRemovBook == null) {
			jButtonRemovBook = new JButton();
			jButtonRemovBook.setBounds(new Rectangle(436, 384, 195, 47));
			jButtonRemovBook.setText("Remove Book From Catalog");
			jButtonRemovBook.addActionListener(this);
		}
		return jButtonRemovBook;
	}

}
